use serde::{Serialize, Deserialize};
use sqlx::{Database, FromRow};
use chrono::{NaiveDateTime, Datelike};
use chrono::serde::MilliSecondsTimestampVisitor;

#[derive(sqlx::FromRow,Debug, Serialize,Deserialize)]
pub struct GroupMessage {
    pub time: String,
    pub list: Vec<Message>,
}


impl GroupMessage {

    pub fn new(time1: NaiveDateTime)->GroupMessage{
        let time_str=time1.format("%Y-%m-%d %H:%M:%S").to_string();
        GroupMessage{time:time_str,list:Vec::new()}
    }
}



#[derive(FromRow)]
pub struct MessageNum {
    pub num: i32,
}

#[derive(FromRow,Debug, Serialize, Deserialize)]
pub struct Message {
    pub id: i32,
    pub user_id: i32,
    pub value: String,
    pub mold: i32,
    pub is_read: i32,
    pub receive_id: i32,
    pub create_time: String,
}

impl Message {
    pub fn new_message(&mut self) -> Message {
        Message {
            id: self.id,
            user_id: self.user_id,
            value: self.value.clone(),
            mold: self.mold,
            is_read: self.is_read,
            receive_id: self.receive_id,
            create_time: self.create_time.clone(),
        }
    }
}

#[derive(Debug,Serialize, Deserialize)]
pub struct BaseChatValueBean<T: Serialize> {
    pub data:T

}

#[derive(FromRow, Serialize, Deserialize)]
pub struct MessageList {
    pub id:i32,
    pub send_id: i32,
    pub receive_id: i32,
    pub num: i32,
    pub last_message: String,
    pub last_time: String,
    pub send_nick: String,
    pub send_logo: String,
    pub receive_nick: String,
    pub receive_logo: String,
}
//
// impl MessageList {
//     pub fn new(send_id: i32,
//                receive_id: i32,
//                num: i32,
//                last_message: String,
//                last_time: String, ) -> MessageList {
//         MessageList {
//             send_id,
//             receive_id,
//             num,
//             last_message,
//             last_time,
//             send_nick: "".to_string(),
//             send_logo: "".to_string(),
//             receive_nick: "".to_string(),
//             receive_logo: "".to_string(),
//         }
//     }
// }
//

#[derive(FromRow,Serialize,Deserialize)]
pub struct ChatUser {
    pub id: i32,
    pub phone:i64,
    pub nick: String,
    pub logo: String,

}